<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var \Magento\Captcha\Block\Captcha\DefaultCaptcha $block */

/** @var \Magento\Captcha\Model\DefaultModel $captcha */
$captcha = $block->getCaptchaModel();
?>
<div class="admin__field _required">
    <label for="captcha" class="admin__field-label">
        <span><?php echo $block->escapeHtml(__('Please enter the letters from the image')) ?></span>
    </label>
    <div class="admin__field-control">
        <input
            id="captcha"
            class="admin__control-text"
            type="text"
            name="<?php echo $block->escapeHtmlAttr(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE) ?>[<?php echo $block->escapeHtml($block->getFormId())?>]"
            data-validate="{required:true}"/>
        <?php if ($captcha->isCaseSensitive()) :?>
            <div class="admin__field-note">
                <span><?php echo $block->escapeHtml(__('<strong>Attention</strong>: Captcha is case sensitive.'), ['strong']) ?></span>
            </div>
        <?php endif; ?>
    </div>
</div>
<div class="admin__field field-captcha">
    <img
        id="captcha-reload"
        class="captcha-reload"
        src="<?php echo $block->escapeUrl($block->getViewFileUrl('Magento_Captcha::reload.png')) ?>"
        alt="<?php echo $block->escapeHtmlAttr(__('Reload captcha')) ?>"/>
    <img
        id="<?php echo $block->escapeHtmlAttr($block->getFormId()) ?>"
        width="<?php /* @noEscape */ echo (float) $block->getImgWidth() ?>"
        height="<?php /* @noEscape */ echo (float) $block->getImgHeight() ?>"
        src="<?php echo $block->escapeUrl($captcha->getImgSrc()) ?>" />
</div>
<script>
    require(["prototype", "mage/captcha"], function(){

//<![CDATA[
        var captcha = new Captcha('<?php echo $block->escapeJs($block->escapeUrl($block->getRefreshUrl())) ?>', '<?php echo $block->escapeJs($block->escapeHtml($block->getFormId())) ?>');

        $('captcha-reload').observe('click', function () {
            captcha.refresh(this);
        });

//]]>

    });
</script>
